// Extended Precision
// The interface is designed to serve higher-level interfaces and leave the error check to higher-level interfaces.
// The interface is as simple as possible so that some of the functions can be implemented in assembly language, if performance considerations necessitate.
// The interface is for unsigned integer.

#ifndef XP_INCLUDED
#define XP_INCLUDED

#define T XP_T // Extended Precision

typedef unsigned char *T;

int           XP_length(int n, T x);
unsigned long XP_fromint(int n, T z, unsigned long u);
unsigned long XP_toint(int n, T x);
int           XP_cmp(int n, T x, T y);

int XP_add(int n, T z, T x, T y, int carry);
int XP_sub(int n, T z, T x, T y, int borrow);
int XP_sum(int n, T z, T x, int y);
int XP_diff(int n, T z, T x, int y);
int XP_neg(int n, T z, T x, int carry);

int XP_mul(T z, int n, T x, int m, T y);
int XP_product(int n, T z, T x, int y);

int XP_div(int n, T q, T x, int m, T y, T r, T tmp);
int XP_quotient(int n, T z, T x, int y);

void XP_lshift(int n, T z, int m, T x, int s, int fill);
void XP_rshift(int n, T z, int m, T x, int s, int fill);

int   XP_fromstr(int n, T z, const char *str, int base, char **end);
char* XP_tostr(char *str, int size, int base, int n, T x);

#undef T

#endif

